import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_picker/image_picker.dart';
import 'package:sph_driver/AppConfig/ShowDialog.dart';

import '../../AppConfig/Config.dart';
import '../../AppConfig/LocalStorage.dart';
import '../../Authentication/AuthenticationModel/QualificationsModel.dart';
import '../../http/api.dart';
import '../../l10n/messages.dart';
import 'package:image/image.dart' as img;

import '../EditInformation/EditCarCard.dart';
import '../EditInformation/ShowImageView.dart';

class FleetRoadView extends StatefulWidget {
  const FleetRoadView({super.key, required this.dataMap});
  final Map dataMap;
  @override
  State<FleetRoadView> createState() => _FleetRoadViewState();
}

class _FleetRoadViewState extends State<FleetRoadView> {
  List titleList=["道路运输证号","业户名称","地址","车辆号牌","经营许可证号","车辆类型","车辆尺寸","发证日期"];
  List titleList2=["道路运输证号","业户名称","地址","车辆号牌","经营许可证号","车辆类型","车辆尺寸","发证日期","过期日期"];
  List dataList =["","","","","","","",""];
  List dataList2 =["","","","","","","","",""];

  late String ChooseIndex="";
  final ImagePicker picker = new ImagePicker();
  //用户本地图片
  File? _userImage;
  File? _userImage2;//存放获取到的本地路径
  int oneCheck =1;
  String cardImgStr="";
  String cardImgStr2="";
  Map dataMap={};
  String getfrontPath="";
  bool isEdit=true;
  bool isShowError=false;
  TextEditingController _nametextEditingController = TextEditingController();
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    if(widget.dataMap['roadTransportCertificateInfo']!=null) {
      isEdit=false;
      dataList2 = [
        widget.dataMap['roadTransportCertificateInfo']['transportNum'],
        widget.dataMap['roadTransportCertificateInfo']['owner'],
        widget.dataMap['roadTransportCertificateInfo']['ownerAddress'],
        widget.dataMap['roadTransportCertificateInfo']['vehicleNum'],
        widget.dataMap['roadTransportCertificateInfo']['licenceNum'],
        widget.dataMap['roadTransportCertificateInfo']['vehicleType'],
        widget.dataMap['roadTransportCertificateInfo']['vehicleSize'],
        widget.dataMap['roadTransportCertificateInfo']['issueDate'],
        widget.dataMap['roadTransportCertificateInfo']['expiryDate']
      ];
    }
    if(widget.dataMap['roadTransportCertificateInfo']!=null)
      getfrontPath=widget.dataMap['roadTransportCertificateInfo']['frontPath'];
  }
  QualiModel qualiModel =QualiModel(DriverPic: "", DriverPic2: "", name: "", MesNum: "", MesType: "",
      EndTime: "", RoadNum: "", ConName: "", Adress: "", CarNum: "", ConNum: "",
      CarSytle: "", CarLength: "", AddTime: "");
  void uploadOcrAction()  async{
    String? drvId=await UserIdManager.getUserID();
    ApiManager.postData(
      context,
      'api/system/dev/ocr/doOcr',
      {
        "typeKey":"fleet_"+drvId!,
        "type": "RTC",
        "frontFileFormat": "jpg",
        "frontData": cardImgStr,
        "backFileFormat":"",
        "backData": "",
      },
          (responseData) {
        setState(() {
          BrnToast.show(
            "识别成功",
            context,
            duration: BrnDuration.short,
          );
          dataMap=responseData['data']['result'];
          dataList2=[dataMap['businessCertificate'],dataMap['ownerName'],dataMap['ownerAddress'],dataMap['vehicleNumber'],dataMap['businessCertificate'],
            dataMap['vehicleType'],dataMap['vehicleSize'],dataMap['issueDate']];
          getfrontPath=responseData['data']['frontPath'];
        });
      },
    );
  }
  void uploadRtcOcrAction()  {


    dio.interceptors.add(InterceptorsWrapper(
        onRequest: (options, handler) async {
          options.headers["satoken"] = await TokenManager.getToken();
          return handler.next(options);
        }
    ));
    dio
        .post(
      MyServiceUrl.header+'api/system/dev/ocr/doOcr',
      data: {

        "type": "RTC",
        "frontFileFormat": "JPG",
        "frontData": cardImgStr2,
        "backFileFormat":"",
        "backData": "",
      },
      options: Options(
        sendTimeout: Duration(seconds: 2),
        receiveTimeout: Duration(seconds: 5),
      ),

    )
        .then((r) {
      setState(() {
        print(r);
        Map<String, dynamic> jsonMap = json.decode(
            r.toString());
        // 获取code和data
        String code = jsonMap['code'].toString();
        if (code == "200") {
          print("code：$code");
          BrnToast.show(
            "识别成功",
            context,
            duration: BrnDuration.short,
          );
        }
      });
    }).catchError((error) {
      print(error);
      ;
    });
  }
  String imageToBase64(File imageFile) {
    List<int> imageBytes = imageFile.readAsBytesSync();
    String base64String = base64Encode(Uint8List.fromList(imageBytes));

    return base64String;
  }


  void printImageMemorySize(File imageFile) {
    List<int> imageBytes = imageFile.readAsBytesSync();
    print('Original Image Memory Size: ${imageBytes.length} bytes');
  }

  Future<void> compressImage(File imageFile) async {
    List<int> imageBytes = await imageFile.readAsBytes();
    img.Image image = img.decodeImage(Uint8List.fromList(imageBytes))!;

    // Adjust the quality and size as needed
    img.Image compressedImage = img.copyResize(image, width: 1024);

    List<int> compressedBytes = img.encodeJpg(compressedImage, quality: 80);

    // Create a new File for the compressed image
    File compressedFile = File('${imageFile.path}_compressed.jpg');
    await compressedFile.writeAsBytes(compressedBytes);

    print('Compressed Image Size: ${compressedBytes.length} bytes');

    convertToBase64(compressedFile);
  }

  Future<void> convertToBase64(File imageFile) async {
    List<int> imageBytes = await imageFile.readAsBytes();
    String base64String = base64Encode(imageBytes);
    print('Base64 String: $base64String');

    cardImgStr =base64String;

    uploadOcrAction();

  }
  @override
  Widget build(BuildContext context) {
    var messages = AppLocalizations.of(context)!;
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(

      backgroundColor:Color.fromRGBO(248, 248, 248, 1),
      appBar: AppBar(
        title: Text("道路运输证",style: TextStyle(fontWeight: FontWeight.w300),),
        centerTitle: true,
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
      ),
      body: Column(
        children: [
          Expanded(child:
          ListView(

            children: [

              Container(color: Colors.white,height: 140.h,child:
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  SizedBox(height: 8.h,),
                  Row(
                    children: [
                      SizedBox(width: 18.w,),
                      Text("上传道路运输证(必填)",style: TextStyle(color: Colors.black,fontWeight: FontWeight.w600,fontSize: 14.sp),),
                    ],
                  ),
                  SizedBox(height: 8.h,),
                  Row(
                    children: [
                      SizedBox(width: 18.w,),
                      GestureDetector(
                        child:
                        getfrontPath!=""&&_userImage==null?
                        Stack(
                          children: [
                            Container(
                              height: 90.h,
                              width: 150.w,
                              child:   Image.network(MyServiceUrl.imgHeader+getfrontPath ,height: 90.h,width: 150.w,fit: BoxFit.cover,),
                            ),
                            if(isEdit)
                            Center(
                              child: Image.asset("lib/Images/Authentication/重新上传.png" ,height: 20.h,width: 50.w,),
                            ),
                          ],
                          alignment: Alignment.center,
                        )
                            :getfrontPath!=""&&_userImage!=null?
                        Stack(

                          children: [

                            Container(
                              height: 90.h,
                              width: 150.w,
                              child: Image.file(_userImage!,height: 90.h,width: 150.w,fit: BoxFit.cover,) ,
                            ),
                            if(isEdit)
                              Center(
                                child: Image.asset("lib/Images/Authentication/重新上传.png" ,height: 20.h,width: 50.w,),
                              ),
                          ],
                          alignment: Alignment.center,
                        )

                            :
                        Image.asset("lib/Images/Authentication/上传道路运输证.png" ,height: 90.h,width: 150.w,),
                        onTap: () async{
                          if(isEdit==false){
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                builder: (context) => ShowImageViewer( (MyServiceUrl.imgHeader+getfrontPath).toString()),
                              ),
                            );
                          }else {
                            showModalBottomSheet(context: context,
                                builder: (BuildContext context) {
                                  return Container(
                                    decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(10))),
                                    child:
                                    Stack(

                                      children: [

                                        Column(
                                          mainAxisSize: MainAxisSize.min,
                                          mainAxisAlignment: MainAxisAlignment
                                              .center,

                                          children: [

                                            Row(
                                              mainAxisAlignment: MainAxisAlignment
                                                  .end,
                                              children: [
                                                IconButton(onPressed: () {
                                                  Navigator.of(context).pop();
                                                },
                                                    icon: Icon(Icons.close,
                                                      color: MyColors
                                                          .textColor,)),
                                              ],
                                            ),
                                            Text(messages["示例"],
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontSize: 14.sp),),
                                            SizedBox(height: 8.h,),
                                            Image.asset(
                                              'lib/Images/Authentication/道路运输证示例图.png',
                                              width: 2270.w, height: 145.h,),


                                            SizedBox(height: 8.h,),
                                            Text(messages["请按照示例上传"],
                                              style: TextStyle(
                                                  color: Color.fromRGBO(
                                                      102, 102, 102, 1)),),
                                            Text(
                                              messages["模糊、遮挡会导致证件无法识别，认证不通过"],
                                              style: TextStyle(
                                                  color: Color.fromRGBO(
                                                      102, 102, 102, 1)),),
                                            SizedBox(height: 8.h,),
                                            Text(messages["上传照片"],
                                              style: TextStyle(
                                                  color: Colors.black,
                                                  fontWeight: FontWeight.w600,
                                                  fontSize: 18.sp),),
                                            SizedBox(height: 10.h,),
                                            Row(
                                              children: [
                                                SizedBox(width: 38.w,),
                                                GestureDetector(
                                                  child: Column(
                                                    children: [
                                                      Image.asset(
                                                        "lib/Images/Authentication/相册icon.png",
                                                        width: 35.w,
                                                        height: 35.h,),
                                                      Text(messages["相册"],
                                                        style: TextStyle(
                                                            color: Colors
                                                                .black),),

                                                    ],

                                                  ),
                                                  onTap: () async {
                                                    Navigator.of(context).pop();
                                                    final pickedFile = await picker
                                                        .pickImage(
                                                        source: ImageSource
                                                            .gallery);

                                                    if (pickedFile != null) {
                                                      setState(() {
                                                        oneCheck = 1;
                                                        _userImage = File(
                                                            pickedFile.path);
                                                        printImageMemorySize(
                                                            _userImage!);
                                                        print(_userImage);
                                                        compressImage(
                                                            _userImage!);
                                                      });
                                                    }
                                                  },
                                                ),

                                                SizedBox(width: 38.w,),
                                                GestureDetector(
                                                  child: Column(
                                                    children: [
                                                      Image.asset(
                                                        "lib/Images/Authentication/拍照icon.png",
                                                        width: 35.w,
                                                        height: 35.h,),
                                                      Text(messages["拍照"],
                                                        style: TextStyle(
                                                            color: Colors
                                                                .black),),

                                                    ],

                                                  ),
                                                  onTap: () async {
                                                    Navigator.of(context).pop();
                                                    final pickedFile = await picker
                                                        .pickImage(
                                                        source: ImageSource
                                                            .camera);

                                                    if (pickedFile != null) {
                                                      setState(() {
                                                        oneCheck = 1;
                                                        _userImage = File(
                                                            pickedFile.path);
                                                        printImageMemorySize(
                                                            _userImage!);
                                                        print(_userImage);
                                                        compressImage(
                                                            _userImage!);
                                                      });
                                                    }
                                                  },
                                                ),

                                              ],
                                            ),
                                            SizedBox(height: 30.h,),
                                          ],

                                        ),

                                      ],

                                    ),
                                  );
                                });
                          }
                        },
                      ),
                    ],
                  ),

                ],
              )

              ),

              SizedBox(height: 8.h,),
              Container(
                margin: EdgeInsets.only(left: 8.w,right: 8.w),
                height: 430.h,
                child:  ListView.separated(
                    physics: NeverScrollableScrollPhysics(),
                    itemCount:9,
                    separatorBuilder: (BuildContext context, int index) {
                      return Container(  // 这里使用 Divider 作为分隔符
                        color: Color.fromRGBO(248, 248, 248, 1),
                        height: 8.h,  // 分隔符的高度
                      );
                    },
                    itemBuilder:(context, index) {
                      return Padding(padding:

                      EdgeInsets.only(left: 8.w,right: 8.w),
                        child:  GestureDetector(
                            child: Container(height: 40.h,
                              decoration: BoxDecoration(
                                  border: Border.all(
                                    color:isShowError==true&&dataList[index]==''? Colors.red:Colors.white, // 边框颜色
                                    width: 0.5, // 边框宽度
                                  ),
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(10))),
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Row(
                                    children: [
                                      SizedBox(width: 8.h,),
                                      Text(titleList2[index],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                    ],
                                  ),
                                  Row(
                                    children: [

                                      Container(
                                        width: screenSize.width-180.w,
                                        child: Text(dataList2[index].toString(),textAlign: TextAlign.right,style: TextStyle(color:Colors.black,overflow:TextOverflow.ellipsis,fontSize: 14.sp ),),
                                      ),
                                      isEdit?
                                      Icon(Icons.arrow_forward_ios,color: MyColors.authTipColor,size: 20,):SizedBox(width: 10.w,),
                                    ],
                                  ),



                                ],
                              ),
                            ),
                            onTap: () async {
                              if (isEdit) {
                                if (index == 7) {
                                  final result = await showModalBottomSheet(
                                    context: context,
                                    builder: (BuildContext context) {
                                      return dataTimeSheet(
                                      );
                                    },
                                  );

                                  if (result != null) {
                                    String mounth = "";
                                    String day = "";

                                    setState(() {
                                      if (result[1]
                                          .toString()
                                          .length == 1) {
                                        mounth = result[1].toString().padLeft(
                                            2, '0');
                                      } else {
                                        mounth = result[1].toStringAsFixed(0);
                                      }
                                      if (result[2]
                                          .toString()
                                          .length == 1) {
                                        day = result[2].toString().padLeft(
                                            2, '0');
                                      } else {
                                        day = result[2].toStringAsFixed(0);
                                      }

                                      String Time = result[0].toString() + "-" +
                                          mounth + "-" + day;
                                      dataList2[7] = Time;
                                      qualiModel.AddTime = Time;
                                      _nametextEditingController.text =
                                          qualiModel.AddTime;
                                    });
                                  }
                                }else if (index == 8) {
                                  final result = await showModalBottomSheet(
                                    context: context,
                                    builder: (BuildContext context) {
                                      return dataTimeSheet(
                                      );
                                    },
                                  );

                                  if (result != null) {
                                    String mounth = "";
                                    String day = "";

                                    setState(() {
                                      if (result[1]
                                          .toString()
                                          .length == 1) {
                                        mounth = result[1].toString().padLeft(
                                            2, '0');
                                      } else {
                                        mounth = result[1].toStringAsFixed(0);
                                      }
                                      if (result[2]
                                          .toString()
                                          .length == 1) {
                                        day = result[2].toString().padLeft(
                                            2, '0');
                                      } else {
                                        day = result[2].toStringAsFixed(0);
                                      }

                                      String Time = result[0].toString() + "-" +
                                          mounth + "-" + day;
                                      dataList2[8] = Time;
                                      qualiModel.EndTime = Time;
                                      _nametextEditingController.text =
                                          qualiModel.EndTime;
                                    });
                                  }
                                } else {
                                  _nametextEditingController.text =
                                  dataList2[index];
                                  showModalBottomSheet(
                                      isDismissible: false,
                                      context: context,

                                      builder: (BuildContext context) {
                                        return Container(

                                          color: Color.fromRGBO(
                                              255, 255, 255, 1),
                                          child: Column(

                                            children: [

                                              SizedBox(height: 8.h,),
                                              Row(
                                                mainAxisAlignment: MainAxisAlignment
                                                    .spaceBetween,
                                                children: [
                                                  TextButton(onPressed: () {
                                                    Navigator.of(context)
                                                        .pop();
                                                    setState(() {
                                                      if (index == 0) {
                                                        qualiModel.RoadNum =
                                                        dataList2[index];
                                                      } else if (index == 1) {
                                                        qualiModel.ConName =
                                                        dataList2[index];
                                                      } else if (index == 2) {
                                                        qualiModel.Adress =
                                                        dataList2[index];
                                                      } else if (index == 3) {
                                                        qualiModel.CarNum =
                                                        dataList2[index];
                                                      } else if (index == 4) {
                                                        qualiModel.ConNum =
                                                        dataList2[index];
                                                      } else if (index == 5) {
                                                        qualiModel.CarSytle =
                                                        dataList2[index];
                                                      } else if (index == 6) {
                                                        qualiModel.CarLength =
                                                        dataList2[index];
                                                      } else if (index == 7) {
                                                        qualiModel.AddTime =
                                                        dataList2[index];
                                                      } else if (index == 7) {
                                                        qualiModel.EndTime =
                                                        dataList2[index];
                                                      }

                                                      _nametextEditingController
                                                          .text =
                                                      dataList2[index];
                                                    });
                                                  },
                                                      child: Text(
                                                        messages["取消"],
                                                        style: TextStyle(
                                                            color: Colors
                                                                .black),)),
                                                  Text(
                                                    titleList[index] + "输入",
                                                    style: TextStyle(
                                                        color: Colors.black,
                                                        fontSize: 16.sp,
                                                        fontWeight: FontWeight
                                                            .w600),),
                                                  TextButton(onPressed: () {
                                                    Navigator.of(context).pop();

                                                    setState(() {
                                                      if (index == 0) {
                                                        dataList2[index] =
                                                            qualiModel.RoadNum;
                                                      } else if (index == 1) {
                                                        dataList2[index] =
                                                            qualiModel.ConName;
                                                      } else if (index == 2) {
                                                        dataList2[index] =
                                                            qualiModel.Adress;
                                                      } else if (index == 3) {
                                                        dataList2[index] =
                                                            qualiModel.CarNum;
                                                      } else if (index == 4) {
                                                        dataList2[index] =
                                                            qualiModel.ConNum;
                                                      } else if (index == 5) {
                                                        dataList2[index] =
                                                            qualiModel.CarSytle;
                                                      } else if (index == 6) {
                                                        dataList2[index] =
                                                            qualiModel
                                                                .CarLength;
                                                      } else if (index == 7) {
                                                        dataList2[index] =
                                                            qualiModel.AddTime;
                                                      } else if (index == 8) {
                                                        dataList2[index] =
                                                            qualiModel.EndTime;
                                                      }

                                                      _nametextEditingController
                                                          .text =
                                                      dataList2[index];
                                                    });
                                                  },
                                                    child: Text(
                                                      messages["确定"],
                                                      style: TextStyle(
                                                          color: Color.fromRGBO(
                                                              231, 112, 27,
                                                              0.85)),),),
                                                ],
                                              ),
                                              SizedBox(height: 8.h,),
                                              Container(

                                                margin: EdgeInsets.only(
                                                    left: 18.w,
                                                    right: 18.w),
                                                decoration: BoxDecoration(
                                                  borderRadius: BorderRadius
                                                      .circular(30.0),

                                                ),
                                                child: TextField(

                                                    controller: _nametextEditingController,

                                                    style: TextStyle(
                                                      color: Colors.black,
                                                    ),
                                                    decoration: InputDecoration(
                                                      filled: true,
                                                      fillColor: Color.fromRGBO(
                                                          249, 249, 249, 1),
                                                      border: InputBorder.none,


                                                    ),
                                                    onChanged: (text) {
                                                      setState(() {
                                                        if (index == 0) {
                                                          qualiModel.RoadNum =
                                                              text;
                                                        } else if (index == 1) {
                                                          qualiModel.ConName =
                                                              text;
                                                        } else if (index == 2) {
                                                          qualiModel.Adress =
                                                              text;
                                                        } else if (index == 3) {
                                                          qualiModel.CarNum =
                                                              text;
                                                        } else if (index == 4) {
                                                          qualiModel.ConNum =
                                                              text;
                                                        } else if (index == 5) {
                                                          qualiModel.CarSytle =
                                                              text;
                                                        } else if (index == 6) {
                                                          qualiModel.CarLength =
                                                              text;
                                                        } else if (index == 7) {
                                                          qualiModel.AddTime =
                                                              text;
                                                        }
                                                      });
                                                    }
                                                ),
                                              ),

                                            ],
                                          ),
                                        );
                                      });
                                }
                              }
                            }
                        ),
                      );
                    }
                ),
              ),
            ],
          ),
          ),
          Container(
            height: 80.h,
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                    height: 40.h ,
                    margin: EdgeInsets.only(left: 30.w,right: 30.w),
                    decoration: BoxDecoration(
                        color:MyColors.themeColor,
                        borderRadius: BorderRadius.all(Radius.circular(30))),

                    width: double.infinity,


                    child: TextButton(
                        child: Text(isEdit?"提交审核":"编辑",style: TextStyle(color: Colors.white,fontSize: 14.sp,fontWeight: FontWeight.w600),),

                        onPressed: ()async {
                          if (isEdit == false) {
                            setState(() {
                              isEdit=true;
                            });
                          } else {
                            isShowError=true;
                            if (dataList2[0] == "") {
                              BrnToast.show("请输入道路运输证号", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[1] == "") {
                              BrnToast.show(
                                "请输入业户名称", context, duration: BrnDuration
                                  .short,);
                            }
                            else if (dataList2[2] == "") {
                              BrnToast.show("请输入地址", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[3] == "") {
                              BrnToast.show("请输入车辆号码", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[4] == "") {
                              BrnToast.show("请输入经营许可证号", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[5] == "") {
                              BrnToast.show("请输入车辆类型", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[6] == "") {
                              BrnToast.show("请输入车辆尺寸", context,
                                duration: BrnDuration.short,);
                            }
                            else if (dataList2[7] == "") {
                              BrnToast.show("请选择发证日期", context,
                                duration: BrnDuration.short,);
                            }
                            // else if (getfrontPath == "") {
                            //   BrnToast.show("请添加从业资格证图片", context,
                            //     duration: BrnDuration.short,);
                            // }
                            else {
                              String? drvId = await UserIdManager.getUserID();
                              if(widget.dataMap['roadTransportCertificateInfo']!=null){
                                ApiManager.postData(
                                  context,
                                  'api/auth/driver/vehicle/editRoadTransportCertificateInfoByCaptain',
                                  {
                                    "vehicleId":widget.dataMap['id'],
                                    "saveOrUpdate": 0,
                                    "driverId": drvId,
                                    "owner": dataList2[1],
                                    "backPath": "",
                                    // "frontPath":"sph56/driver/1781255212293775361/avatar/1781255212293775361_avatar.png",
                                    "frontPath": getfrontPath,
                                    "issueDate": dataList2[7],
                                    "licenceNum": dataList2[4],
                                    "vehicleNum": dataList2[3],
                                    "ownerAddress": dataList2[2],
                                    "vehicleSize": dataList2[6],
                                    "vehicleType": dataList2[5],
                                    "transportNum": dataList2[0],
                                    "expiryDate": dataList2[8]
                                  },
                                      (responseData) async {
                                    BrnToast.show("提交成功", context,);
                                    Navigator.pop(context, "success");
                                  },
                                );
                              }else {
                                ApiManager.postData(
                                  context,
                                  'api/auth/driver/vehicle/editRoadTransportCertificateInfoByCaptain',
                                  {
                                    "saveOrUpdate": 0,
                                    "driverId": drvId,
                                    "owner": dataList2[1],
                                    "backPath": "",
                                    // "frontPath":"sph56/driver/1781255212293775361/avatar/1781255212293775361_avatar.png",
                                    "frontPath": getfrontPath,
                                    "issueDate": dataList2[7],
                                    "licenceNum": dataList2[4],
                                    "vehicleNum": dataList2[3],
                                    "ownerAddress": dataList2[2],
                                    "vehicleSize": dataList2[6],
                                    "vehicleType": dataList2[5],
                                    "transportNum": dataList2[0],
                                    "expiryDate": dataList2[8]
                                  },
                                      (responseData) async {
                                    BrnToast.show("提交成功", context,);
                                    Navigator.pop(context, "success");
                                  },
                                );
                              }
                            }
                          }
                        }
                    )
                ),
              ],
            ),
          ),



          // }),
        ],
      ),



    );
  }
}

